In article <4e1o5v$6i8@seagoon.newcastle.edu.au>, peter@tesla.newcastle.edu.au wrote:
> The obvious question, though, is why you would want to do this.
> Such operations are common in C programming because C lacks
> more elegant ways to get the job done. In Modula-2, there are
> certainly situations where you want to do weird hardware-dependent
> things and break the type system, but those situations should
> arise only when writing very low-level modules. In most other
> cases, there's almost always a better way to do the job.
I don't *want* to do this, I didn't find any other way in my case.
<BEGIN WEIRD DESCRIPTION OF MY PROBLEM>
I'm adding Modula code to a project that was 100 percent done in assembler.
I have some global variables that need to be transmitted thru MIDI SYSEX.
I've defined a SYSEX protocoll that allows me to read/write those vars.
SYSEX PARAM_DATA from length val_1 .. val_n SYSEXEND (* sets params to values *)
SYSEX PARAM_REQ from length SYSEXEND (* answered by PARAM_DATA *)
(* Lets assume the vars are: *)
VAR
alpha : CARDINAL; (* idx: 0 *)
beta : CARDINAL; (* idx: 1 *)
gamma : CARDINAL; (* idx: 2 *)
(* My procedure could now look like this *)
PROCEDURE ReadParam( from : CARDINAL, to :CARDINAL);
VAR
i : CARDINAL;
BEGIN
FOR i:= from TO to DO
CASE i OF
| 0 : alpha := ReadMIDICardinal();
| 1 : beta := ReadMIDICardinal();
| 2 : gamma := ReadMIDICardinal();
(* ... *)
ELSE
(* ignore *)
END; (* CASE i *)
END; (* FOR i *)
END ReadParam;
(* ... similar for PROCEDURE WriteParam *)
(* or I could use pointer arithmetic to change those values directly. *)
<END WEIRD DESCRIPTION OF MY PROBLEM>
I admit that I don't like the clean Modula solution, because the code will get huge, even if it looks neat. (The variables to change might one day be in the hundreds)
Is there a better way to do this? Maybe like having an array at the same place. (I know, that's C too)